package com.it.Demo2;

import java.util.Scanner;

public class Game {
    Person person;
    Computer computer;
    int count;
    public void initial(){
        person=new Person();
        computer=new Computer();
        count=0;//回合数
    }
    public void startGame(){
        initial();
        System.out.println("------------欢迎进入游戏----------");
        System.out.println("--------------猜拳开始-----------");
        System.out.println("--------------------------------");
        System.out.println("出拳的规则：1.剪刀   2.石头   3.布");
        System.out.println("请选择对方的角色（1.刘备  2.孙权  3.曹操）");
        Scanner input=new Scanner(System.in);
        int role=input.nextInt();
        if(role==1){
            computer.name="刘备";
        }else if(role==2){
            computer.name="孙权";
        }else if(role==3){
            computer.name="曹操";
        }
        System.out.println("你选择了"+computer.name+"对战");

        System.out.println("要开始吗？（y/n）");
        String flag=input.next();
        int perFirst;
        int compFirst;
        while (flag.equals("y")){
            perFirst= person.showF();
            compFirst=computer.showF();
            if ((perFirst==1&&compFirst==1)||(perFirst==2&&compFirst==2)||(perFirst==3&&compFirst==3)){
                System.out.println("结果：平局");
            }else if ((perFirst==1&&compFirst==2)||(perFirst==2&&compFirst==3)||(perFirst==3&&compFirst==1)){
                System.out.println("结果：你胜利了");
                person.score++;
            }else {
                System.out.println("结果：你输了");
                computer.score++;
            }
            count++;
            System.out.println("是否开始下一轮（y/n）");
            flag=input.next();
        }
        showResult();
    }
    public void showResult(){
        System.out.println("------------------------------");
        System.out.println(computer.name+"VS"+person.name);
        System.out.println("对战的次数"+count);
        int result=calcResult();
        if (result==1){
            System.out.println("结果：打成平手");
        }else if (result==2){
            System.out.println("结果：胜出");
        }else {
            System.out.println("结果：下次加油吧");
        }
        System.out.println("------------------------------");
    }

    public int calcResult(){
        if (person.score==computer.score){
            return 1;
        }else if (person.score>computer.score){
            return 2;
        }else {
            return 3;
        }
    }
}
